Markdown: whitelist aria-label
for curly brackets
#4095
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog Entry
Fixed
aria-label
for links in Markdown and skip unrecognized attributes or invalid curly brackets, by @compulim, in PR #4095Description
We should whitelist
aria-label
(as curly brackets) in Markdown and skip unrecognized or invalid form. Thearia-label
attribute is added by PR #3022.This will continue to enable
aria-label
in[Link](https://.../){aria-label="This is a link"}
.But it will skip
Hello {1}
. As{1}
could be used for text-templating (related to #3165).Design
Curly brackets pattern
I tested few undocumented behavior of
markdown-it-attrs
:[Link](...){aria-label}
or[Link](...){aria-label=}
will addaria-label
attribute without value (boolean true)[Link](...){aria-label=abc}
will addaria-label="abc"
[Link](...){aria-label ="abc"}
will addaria-label
attribute without value (note the space before/after equal sign)[Link](...){ aria-label="abc" }
will addaria-label="abc"
markdown-it-attrs
As we only allowlist
aria-label
, to solve the{1}
case, I come up with these as the solely supported patterns for curly brackets:{aria-label}
{aria-label=ABC}
{aria-label="ABC"}
Other patterns will be considered as invalid, such as including unsupported attributes.
Invalid pattern should be skipped by
markdown-it-attrs
and left untouched.Controlling what to process (or skip)
markdown-it-attrs
will process all curly brackets and remove them from content, even though they are invalid or not specified by the whitelist attributes.There are very few options we can use to control the behavior
markdown-it-attrs
. Thus, we used allowlist pattern by using regular expression to convert the curly brackets{}
into a rarely-used set of characters⟬⟭
(white tortoise shell brackets).Then, we ask
markdown-it-attrs
to only look at these shell brackets.This effectively allow us to control what the
markdown-it-attrs
could see.Specific Changes
renderMarkdown.ts
aria-label
markdown-it-attrs
could seeCHANGELOG.md
Review Checklist
Accessibility reviewed (tab order, content readability, alt text, color contrast)Browser and platform compatibilities reviewedCSS styles reviewed (minimal rules, noz-index
)Documents reviewed (docs, samples, live demo)Internationalization reviewed (strings, unit formatting)package.json
andpackage-lock.json
reviewed